Rust: Fix type inference for library parameters#19658
Merged
hvitved merged 2 commits intogithub:mainfrom Jul 11, 2025
Merged
Conversation
c4d46f2 to
07fe1bf
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes type inference for library parameters by switching from pattern-based inference to using explicit type representations, updates related test expectations for Pin methods, and renames a debug helper to match its new signature.
- Replace
inferAnnotatedTypeon parameter patterns withTypeMention.resolveTypeAtfor library parameters - Adjust modeled dataflow tests and expected outputs to account for
into_inner_unchecked - Rename
debugResolveMethodCallExprto acceptMethodCallinstead ofMethodCallExpr
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| rust/ql/test/library-tests/dataflow/modeled/main.rs | Reorder imports and update test comment for Pin::into_inner_unchecked |
| rust/ql/test/library-tests/dataflow/modeled/inline-flow.expected | Update expected model entries and edge labels |
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Use TypeMention.resolveTypeAt for parameter types and rename debug function signature |
Comments suppressed due to low confidence (1)
rust/ql/test/library-tests/dataflow/modeled/main.rs:98
- [nitpick] These two imports from
std::pincould be combined into a single statement:use std::pin::{pin, Pin};for clarity and conciseness.
use std::pin::pin;
| Function debugResolveMethodCallExpr(MethodCallExpr mce) { | ||
| mce = getRelevantLocatable() and | ||
| result = resolveMethodCallTarget(mce) | ||
| Function debugResolveMethodCallExpr(MethodCall mc) { |
There was a problem hiding this comment.
[nitpick] The debug function signature and parameter name changed from MethodCallExpr/mce to MethodCall/mc. Consider updating any related comments or docs to prevent confusion when maintaining this helper.
Suggested change
| Function debugResolveMethodCallExpr(MethodCall mc) { | |
| Function debugResolveMethodCall(MethodCall mc) { |
4812c40 to
c4966e8
Compare
c4966e8 to
0ccc4ac
Compare
eba3c69 to
4dda16b
Compare
4dda16b to
bcdd6f5
Compare
6595424 to
b753252
Compare
b753252 to
1d7d45e
Compare
aibaars
approved these changes
Jul 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The old logic relied on parameters having a pattern, which is not the case for parameters extracted from library code.
The updated test output reveals that we do not handle operator calls correctly. For example,Now fixed by #19749.i32implements bothAddandAdd<Rhs = &i32>, and currently we resolve1 + 2to bothaddmethods, which means that2will have reverse-propagated type&i32in addition toi32.DCA (finally) looks good; we gain more call targets without sacrificing performance.